/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package EDT.actions;

import EDT.api.API;
import EDT.form.AjoutCreneauForm;
import EDT.obj.Calendrier;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

/**
 *
 * @author ali
 */
public class AjoutCreneauAction extends org.apache.struts.action.Action {

    /* forward name="success" path="" */
    private static final String SUCCESS = "success";

    /**
     * This is the action called from the Struts framework.
     *
     * @param mapping The ActionMapping used to select this instance.
     * @param form The optional ActionForm bean for this request.
     * @param request The HTTP Request we are processing.
     * @param response The HTTP Response we are processing.
     * @throws java.lang.Exception
     * @return
     */
    @Override
    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        
       AjoutCreneauForm f = (AjoutCreneauForm) form;
        
          
        String m="";
        

     m =        EDT.api.API.AjouterCreneau(f.getKey(),f.getSalle(),f.getPromo(),f.getEc(),f.getInterv(),f.getJour(),f.getGp(),f.getType(),f.getDebut(),f.getFin(),f.getNbrCr(),f.getVisible());

        
    //   m= f.toString();
        
        int annee = EDT.api.API.getAnnee(f.getPromo());
            String periode = "all";
            String formation = API.getNomFormation(f.getPromo());
            Calendrier c = EDT.api.API.getAllCalendrierPromo(f.getKey(),f.getPromo(), periode,f.getNbrPeriode(),f.getGp());
            
            c.setTitre("Emplois du temps " +" "+formation+"<br/>Promotion : "+annee+"/"+(annee+1)+"<br/>Groupe : "+f.getGp());
            request.setAttribute("calendrier", c.perideToTableHTMLClick("modification"));
        
            request.setAttribute("annee", annee);
        
            
            
            request.setAttribute("formation", formation);
            request.setAttribute("promo", f.getPromo());
            request.setAttribute("periode", "all");
            request.setAttribute("nbrPeriode", f.getNbrPeriode());
            request.setAttribute("grp", f.getGp());
     
        if(m.equals("")){
            
            m +="<label style='color:#009F3C;'>le creneau est ajouté avec succès !</label>";

        
        }else{
            m ="<label style='color:red;'>"+ m+"</label>";
        }
        
         
        
        
        request.setAttribute("msg", m);
        //return mapping.findForward("ajout");
        
        return mapping.findForward("calendrierSelect");
    }
}
